package com.qf.medicaldoctoradmin.healthMonitor.monitor.controller;

import com.qf.common.common.R;
import com.qf.common.entity.Monitor;
import com.qf.medicaldoctoradmin.healthMonitor.monitor.service.MonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "健康检测API")
@RestController
@CrossOrigin
@RequestMapping("/health/monitor")
public class MonitorController {
    @Resource
    private MonitorService monitorService;

    @ApiOperation(value = "获取一条用户健康数据详情", notes = "根据登录用户的id，获取登录者的最新的一条数据详情")
    @GetMapping("/selectOne")
    public R selectOne() {
        Monitor monitor = monitorService.selectOne();
        return R.ok(monitor);
    }

    @ApiOperation(value = "更新用户健康数据记录", notes = "根据传入对象的id更新，可更新单个体重/心率/血压数据，未更新的数据保持和原数据相同")
    @PostMapping("/update")
    public R update(@RequestBody Monitor monitor) {
        monitorService.updateOneInfo(monitor);
        return R.ok("更新成功");
    }

    @ApiOperation(value = "删除用户健康数据记录", notes = "不要轻易删除，根据id删除用户完整的一条健康数据记录，时间必须完整，会删除对应日期的体重/心率/血压等记录")
    @PostMapping("/delete")
    public R insert(@RequestBody Monitor monitor) {
        monitorService.delete(monitor);
        return R.ok("删除成功");
    }
}
